package com.zw.stock_sell_storage.controller;

import com.zw.stock_sell_storage.constant.MessageCode;
import com.zw.stock_sell_storage.service.MSGService;
import com.zw.stock_sell_storage.utils.JsonResult;
import com.zw.stock_sell_storage.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/JWTTest")
public class MSGController {
    @Autowired
    private MSGService jwtService;


    @GetMapping("/send")
    public JsonResult sendMsm(String phone){
        JsonResult jsonResult = new JsonResult();
        try {
            //生成随机数
            String code = RandomUtil.getFourBitRandom();
            Map map = new HashMap();
            map.put("code",code);
            boolean b = jwtService.send(map,phone);
            if (!b){
                jsonResult.setMessage(MessageCode.VERIFICATION_CODE_ERROR.message);
                jsonResult.setCode(MessageCode.VERIFICATION_CODE_ERROR.code);
            }
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setCode(MessageCode.ERROR.code);
            jsonResult.setMessage(MessageCode.ERROR.message);
        }
        return jsonResult;
    }
}
